/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */

//#define BOOST_TEST_MODULE File
#include <boost/test/unit_test.hpp>
#include "../config.h"


BOOST_AUTO_TEST_SUITE( FileTest )

const File FILES[] = {
		File::A(),
		File::B(),
		File::C(),
		File::D(),
		File::E(),
		File::F(),
		File::G(),
		File::H(),
		File::NIL()
	};

const char* FILES_STR[] = {"a","b","c","d","e","f","g","h","-"};

const int FILES_LENGTH = 9;

BOOST_AUTO_TEST_CASE( testEqual ) {
	for ( int i = 0; i < FILES_LENGTH; ++i ) {
		File file = FILES[i];
		BOOST_CHECK_EQUAL(file, FILES[i]);
	}
}

BOOST_AUTO_TEST_CASE( testNotEqual ) {
	for ( int i = 0; i < FILES_LENGTH; ++i ) {
		File file1 = FILES[i];
		for ( int j = 0; j < 7; ++j ) {
			File file2 = FILES[j];
			if ( i != j )
				BOOST_CHECK_NE(file1, file2);
		}
	}
}

BOOST_AUTO_TEST_CASE( testToInt ) {
	for ( int i = 0; i < FILES_LENGTH; ++i ) {
		File file = FILES[i];
		BOOST_CHECK_EQUAL(file.toInt(), i);
	}
}

BOOST_AUTO_TEST_CASE( testFromInt ) {
	for ( int i = 0; i < FILES_LENGTH; ++i ) {
		File file;
		file.fromInt(i);
		BOOST_CHECK_EQUAL(file, FILES[i]);
	}
}

BOOST_AUTO_TEST_CASE( testFile_Int ) {
	for ( int i = 0; i < FILES_LENGTH; ++i ) {
		File file = File(i);
		BOOST_CHECK_EQUAL(file, FILES[i]);
	}
}

BOOST_AUTO_TEST_CASE( testInc ) {
	int i = 0;
	File file = File::BEGIN();
	while ( i < FILES_LENGTH - 1 ) {
		BOOST_CHECK_EQUAL(FILES[i], file);
		++file;
		++i;
	}
	BOOST_CHECK_EQUAL(file, File::END());
}

BOOST_AUTO_TEST_CASE( testDec ) {
	int i = FILES_LENGTH - 2;
	File file = File::RBEGIN();
	while ( i >= 0 ) {
		BOOST_CHECK_EQUAL(FILES[i], file);
		--file;
		--i;
	}

	BOOST_CHECK_EQUAL(file, File::REND());
}

BOOST_AUTO_TEST_CASE( toStrTest ) {
	for ( int i = 0; i < FILES_LENGTH; ++i ) {
		File file = FILES[i];

		BOOST_CHECK_EQUAL(file.toStr(), FILES_STR[i]);
	}
}

BOOST_AUTO_TEST_CASE( fromStrTest ) {
	for ( int i = 0; i < FILES_LENGTH; ++i ) {
		File file;
		file.fromStr(FILES_STR[i]);

		BOOST_CHECK_EQUAL(file, FILES[i]);
	}
}


BOOST_AUTO_TEST_SUITE_END()
